package au.edu.unsw.editingtool.db;

import java.sql.SQLException;
import java.util.Hashtable;

import au.edu.unsw.editingtool.global.EditingToolException;
import au.edu.unsw.editingtool.global.GlobalConstant;

public class DBLog extends DBManager {
	
	protected void setupDBMapping() {
		if (MappingTable.size() > 0)
			return;
		MappingTable.put("LogID", "log_id");
		MappingTable.put("LogStatus", "log_status");
		MappingTable.put("Detail", "detail");		
		MappingTable.put("Date", "date");
		MappingTable.put("Username", "username");
		MappingTable.put("PID", "pid");
		MappingTable.put("DSID", "dsid");		
	}
	
	public DBLog() {
		this.table = "log";
		this.primaryKeys = new String[]{"LogID"};
		this.setupDBMapping();
	}
	
	public void addLog(Hashtable<String, String> log) throws EditingToolException, ClassNotFoundException, SQLException {
		this.setTable(this.table, "");		
		log.put("Date", "CURRENT_TIMESTAMP()");		
		this.setColumnValues(log);		
		this.initDB();
		this.insert(false, false);
		this.clean();
	}
}
